package com.basic.business.shift.service.impl;

import com.basic.business.common.constants.Constants;
import com.basic.business.common.redis.RedisCacheUtils;
import com.basic.business.shift.domain.TShiftMgmt;
import com.basic.business.shift.mapper.ITShiftMgmtMapper;
import com.basic.business.shift.service.ITShiftMgmtService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * 班次管理表服务实现类
 *
 * @author zhaoxy_jn@163.com
 */
@Service
public class TShiftMgmtServiceImpl implements ITShiftMgmtService {

    @Resource
    private ITShiftMgmtMapper tShiftMgmtMapper;

    /**
     * 项目启动时，初始化班次信息缓存
     */
    @PostConstruct
    public void init(){
        resetShiftCache();
    }

    @Override
    public List<TShiftMgmt> getNormalShiftInfo() {
        return tShiftMgmtMapper.getNormalShiftInfo();
    }

    /**
     * 重置班次信息缓存
     */
    private void resetShiftCache() {
        // 清空缓存
        RedisCacheUtils.clearCache(Constants.SHIFT_REDIS_KEY + "*");
        // 加载缓存
        loadingShiftCache();
    }

    /**
     * 加载班次信息缓存
     */
    private void loadingShiftCache() {
        RedisCacheUtils.setCacheObject(Constants.SHIFT_REDIS_KEY, getNormalShiftInfo());
    }
}
